<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/1/14
 * Time: 20:15
 */

// 注册路由到api模块的News控制器的read操作
Route::rule('new/:id','api/News/read');

//路由直接渲染模板输出
Route::view('hello/:name','api@index/hello');

//路由闭包+依赖注入
Route::rule('bibao/:name', function (Request $request, $name) {
    $method = $request::method();
    return '[' . $method . '] Hello,' . $name;
});

Route::get('response/:name', function (Response $response, $name) {
    return $response
        ::data('Hello,' . $name)
        ->code(200)
        ->contentType('text/plain');
});

//路由对参数进行限定
Route::get('new1/:id', 'api/News/read')
    ->ext('html');

//路由分组
/*Route::group('api', [
    ':id'   => 'api/News/read',
    ':name' => 'api/News/write',
])->ext('html')->pattern(['id' => '\d+']);*/

Route::group('api', function () {
    Route::get(':id', 'News/read');
    Route::get(':name', 'News/write');
})->prefix('api/')->ext('html')->pattern(['id' => '\d+']);


Route::group('api', function () {
    //资源路由
    Route::resource('book','Book');

    Route::resource('book.comment','Comment');

})->prefix('api/');


Route::alias('test','api/Index');
Route::alias('test', 'api/Index', ['ext' => 'html']);


/*Route::group('api', function () {
    Route::get(':id', 'News/read');
    Route::get(':name', 'News/write');
})->prefix('api/')->ext('html')->pattern(['id' => '\d+'])->append(['group_id'=>1]);*/


